#define _CRT_SECURE_NO_WARNINGS 1
#include "string.h"

namespace wxd
{
	
	void string_test01()
	{
		string s1;
		string s2("Hello World!");
		cout << s1.c_str() << endl;
		cout << s2.c_str() << endl;
		cout << s1.size() << endl;
		cout << s2.size() << endl;
		cout << s2[0] << endl;

		for (int i = 0; i < s2.size(); i++)
		{
			cout << s2[i] << " ";
		}
		cout << endl;
		const string s3("Hello CPP!");
		for (int i = 0; i < s3.size(); i++)
		{
			cout << s3[i] << " ";
		}
		cout << s2.capacity() << endl;
	}
	void string_test02()
	{
		/*const */string s1("Hello World!");
		string::iterator it = s1.begin();
		while (it != s1.end())
		{
			cout << *it++ <<" ";
		}
		cout << endl;

	}
	void string_test03()
	{
		string s1 = "Hello World!";
		cout << s1.c_str() << endl;
		cout << s1.capacity()<<endl;
		s1.push_back('x');
		cout << s1.c_str() << endl;
		cout << s1.capacity() << endl;
		s1.push_back('x');
		cout << s1.c_str() << endl;
		cout << s1.capacity() << endl;
	}

	void string_test04()
	{
		string s1 = "Hello World!";
		//cout << s1.c_str() << endl;
		//cout << s1.capacity() << endl;

		//s1.append("xxx");
		//cout << s1.c_str() << endl;
		//cout << s1.capacity() << endl;

		//s1.append("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
		//cout << s1.c_str() << endl;
		//cout << s1.capacity() << endl;
		/*s1 += 'x';
		cout << s1.c_str() << endl;*/

		//s1 += "XXXXXXXXX";
		char* str = nullptr;
		s1.append(str);
		cout << s1.c_str() << endl;

	}

	void string_test05()
	{
		string s1 = "Hello World!";
		/*s1.insert(5,'x');
		s1.insert(0, 'x');
		s1.insert(s1.size(), 'x');
		cout << s1.c_str() << endl;*/

		s1.insert(5, "xxxx");
		s1.insert(0, "xxxx");
		s1.insert(s1.size(), "xxxx");
		cout << s1.c_str() << endl;
	}
	void string_test06()
	{
		string s1 = "Hello World!";
		//s1.erase(5, 3);
		//s1.erase(5, 1);
		//s1.erase(5, 11111);
		//s1.erase(5);
		//s1.erase(0, 1);
		//s1.erase(6, 3);
		//s1.erase(1);

		cout << s1.c_str() << endl;
	}

	void string_test07()
	{
		string s1 = "Hello world!";
		//size_t find = s1.find('w');
		//size_t find = s1.find('j');
		//size_t find = s1.find("wor");

		//cout << find << endl;
		//string s2 = s1.substr(s1.find('w'));
		string s2 = s1.substr(6);
		cout << s2.c_str() << endl;
		cout << "size = " << s2.size() << endl;
		cout << "capacity = " << s2.capacity() << endl;
	}

	void string_test08()
	{
		/*string s1 = "Hello world!";
		string s2 = "XXX";
		cout << s1 << s2 << endl;*/

		string s1;
		//cin >> s1;
		//cout << s1;
		getline(cin,s1);
		cout << s1;

	}

	void string_test09()
	{
		//string s1 = "Hello World";
		const string s1 = "Hello World";
		string s2;
		string s3;
		s2 = s1;


		cout << s1 << endl;
		cout << s2 << endl;
		//cout << s3 << endl;
	}
	void string_test10()
	{
		string s1 = "Hello World";
		//string s3;
		////string s2 = s1;
		//s3 = s1;

		////cout << s2 << endl;
		//cout << s3 << endl;


		cout << s1.c_str() << endl;


		
	}
	void string_test11()
	{
		string s1 = "Hello World!";
		string s3;
		s3 = s1;
	}
}

int main()
{
	//wxd::string_test01();
	//wxd::string_test02();
	//wxd::string_test03();
	//wxd::string_test04();
	//wxd::string_test05();
	//wxd::string_test06();
	//wxd::string_test07();
	//wxd::string_test08();
	//wxd::string_test09();
	//wxd::string_test10();

	wxd::string_test11();


	/*Test t;
	const char* reta = t.ConstTest();
	cout << reta << endl;*/


	
	return 0;
} 